package com.scedu.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
public class RestFulController {

    //原来访问： http://localhost:8080/add?a=1&b=2
    //RestFul风格 http://localhost:8080/add/a/b
    //指定方法 method = RequestMethod.PUT
    @RequestMapping(value = "/add/{a}/{b}",method = RequestMethod.PUT)
    public String test(@PathVariable Integer a, @PathVariable Integer b, Model model)
     {   Integer result=a + b;
        model.addAttribute("msg","计算的结果是："+result);
         return "test";
     }

    //指定方法 method = RequestMethod.GET
    @RequestMapping(value = "/add/{a}/{b}",method = RequestMethod.GET) //@GetMapping("/add/{a}/{b}")
    //等于@GetMapping("/add/{a}/{b}")
    public String test1(@PathVariable Integer a, @PathVariable Integer b, Model model)
    {   Integer result=a + b;
        model.addAttribute("msg","计算的结果是："+result);
        return "test";
    }
    //指定方法 method = RequestMethod.POST
    //@RequestMapping(value = "/add/{a}/{b}",method = RequestMethod.POST)
    @PostMapping("/add/{a}/{b}") //等价于 @RequestMapping(value = "/add/{a}/{b}",method = RequestMethod.POST)
    public String test2(@PathVariable Integer a, @PathVariable Integer b, Model model)
    {   Integer result=a + b;
        model.addAttribute("msg","计算的结果是："+result);
        return "test";
    }
}
